package Server.ServerCore.Controller;

import Server.ServerCore.Model.Player.PlayerInstance;
import Server.ServerCore.Service.DataPacks.packRequest._21_requst;
import Server.ServerCore.Service.DataPacks.packRespose.bust_response;
import Server.ServerCore.Service.Logic.HandleController;
import Server.ServerCore.Service.Logic.RegisterPack;
import Server.ServerCore.Service.service.PlayerManagerService;
import org.jboss.netty.buffer.ChannelBuffer;
import org.springframework.stereotype.Service;

/**
 * @author :石头哥哥<br/>
 *         Project:21Server
 *         Date: 13-4-11
 *         Time: 上午2:53
 *         1.处理A问题，当指向下一个玩家，没有归并，还是分别显示：如A和2（13/3）
 *         2.当A和k,j,q,10没有显示点数21，此时应该是黑杰克；指向下一个；
 *
 */
@Service
public class _21Controller extends HandleController {
    private static final long serialVersionUID = -7564993834007673484L;

    /**
     * 数据分解具体处理的函数
     *
     * @param buffer buffer
     * @param player player
     */
    @Override
    public void DispatchPack(ChannelBuffer buffer, PlayerInstance player) throws Exception {
        _21_requst requst= (_21_requst) parseObject(buffer,_21_requst.class);

        if (requst.getCircleUnitID()!=5&&player.getNowCrileUnitID()==requst.getCircleUnitID()){
            bust_response bustResponse=new bust_response();
            int now=PlayerManagerService.getNextcircleUnitID(player,requst.getCircleUnitID());
            bustResponse.setNextcircleUnitID(now);
            if (now!=-1){
                player.setNowCrileUnitID(now);
            }
            player.DirectSend(bustResponse.getJsonData(2,9));
        }
    }
    /**
     * 通过spring产生处理数据的controller，储存在数组中
     */
    @Override
    public void InitiController() {
        RegisterPack.GAME_CONTROLLERS[212]=this;
    }
}
